package com.cy.gameserver.service;

import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * Created by tiankai.qin on 18/3/13.
 * 短信服务
 */
@Service
public class SmsService {

    private static final Logger logger = LoggerFactory.getLogger(SmsService.class);

    private final String APPKEY = "24535967";

    private final String APPSECRET = "1896e3470ae4f362bc5f9eb3a26c2c51";

    private final String REQUEST_URL = "http://gw.api.taobao.com/router/rest";

    private final TaobaoClient client = new DefaultTaobaoClient(REQUEST_URL, APPKEY, APPSECRET);


    /**
     * 发送验证码
     * @param tel
     * @param code
     */
    public void sendValidateCode(String tel, String code) {
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        //req.setExtend("123456");
        req.setSmsType("normal");
        req.setSmsFreeSignName("CYook创意平台");
        req.setSmsParamString("{\"number\":\"" + code + "\"}");
        req.setRecNum(tel);
        req.setSmsTemplateCode("SMS_76250016");
        AlibabaAliqinFcSmsNumSendResponse rsp = null;
        try {
            rsp = client.execute(req);
        } catch (ApiException e) {
            logger.info("sms error : " + e);
        }
        logger.info("ali sms:" + rsp.getBody());
    }


}
